import { CalendarIcon } from "lucide-react"; import { useSession } from "next-auth/react"; import Head from "next/head"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { Button } from "~/components/ui/button"; import { Label } from "~/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger, } from "~/components/ui/popover"; import { cn } from "~/lib/utils"; import { api, type RouterOutputs } from "~/utils/api"; import { Textarea } from "~/components/ui/textarea"; import { Calendar } from "~/components/ui/calendar"; import { Checkbox } from "~/components/ui/checkbox"; import { format } from "date-fns"; export default function EditWine() { useSession({ required: true }); const router = useRouter(); const utils = api.useUtils(); const bottleId = router.query.bottleId as string | undefined; const [bottle, setBottle] = useState< RouterOutputs["wine"]["getBottle"] | null >(null); useEffect(() => { if (bottleId === undefined || bottle) return; void utils.wine.getBottle .fetch({ id: parseInt(bottleId) }) .then((wine) => setBottle(wine)); }, [bottleId, bottle, utils.wine.getBottle]); const editBottle = api.wine.editWineBottle.useMutation(); const handleSaveBottle = async () => { if (bottle === null) return; await editBottle.mutateAsync(bottle); await router.push(`/${bottle.wineId}`); }; return ( <>